package com.learn.multi_thread.A_BaseThread.D_DeadThread;

public class DeadThreadForExtend extends Thread {
    static Object objectA = new Object();
    static Object objectB = new Object();

    @Override
    public void run() {
        while (true) {
            if ("线程A".equals(getName())) {
                synchronized (objectA) {
                    System.out.println("线程A获取到了objectA的锁，准备拿B锁");

                    synchronized (objectB) {
                        System.out.println("线程A获取到了objectB的锁，顺利执行完一轮");
                    }
                }
            } else if ("线程B".equals(getName())){
                synchronized (objectB) {
                    System.out.println("线程A获取到了objectB的锁，准备拿A锁");

                    synchronized (objectA) {
                        System.out.println("线程A获取到了objectA的锁，顺利执行完一轮");
                    }
                }
            }
        }
    }
}
